import json
from login1 import *

def write(file,list):
    with open(file, 'w', encoding='utf-8')as f:
        f.write(json.dumps(list))



def func6():
    name, password = input('请输入姓名：'), int(input('请输入密码：'))
    dict1, dict1[name] = {}, password

    return dict1,name


def func3(x):

    with open('files/'+x, 'r', encoding='utf-8')as f:
        return json.loads(f.read())


def func5(x,b='同学'):
    with open('files/'+x, 'r', encoding='utf-8')as f:
        print((f.read())%b)


def func2():
    dict3,name0 = func6()
    list1 = func3('23333.json')
    if dict3 in list1:
        print('重复注册 ')
        func5('new2.txt')
        while True:
            a = input('这里输入：')
            if a == '返回主页':
                return
    else:
        list1.append(dict3)

        write('files/'+name0+'.json',[])
        write('files/23333.json',list1)

    print('注册成功')



def func1():
    dict2,name0 = func6()
    list1 = func3('23333.json')
    if dict2 in list1:
        func5('new1.txt',name0)
        name0 = name00
        man_oper()

    else:
        print('姓名密码错误')
        return


while True:
    func5('new.txt')
    print('=========登录1  注册2======== ')
    chose = input('请选择：')
    if chose == '1':
        func1()
    elif chose == '2':
        func2()
    else:
        print('选择错误，重新输入')
